/**
 * 
 */
package com.sci.web.action.datareportseason.researchmoney;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.sci.web.action.util.BaseAction;
import com.sci.web.bean.Enterprise_Funds;
import com.sci.web.dao.DataReportM_InnovateBaseDao;

/**
 * @author BaiFuyou
 * @date: Nov 10, 2011 9:09:16 AM
 * 
 * 增加一条新的研发经费强度。
 */
public class AddNewResearchMoneyAction extends BaseAction {

	/**
	 * f_sale : f_sale, f_invest : f_invest, f_tech : f_tech, f_research : f_research, f_p : f_p,
	 * 
	 */
	private static final long serialVersionUID = -235491260210800882L;
	@Resource
	private DataReportM_InnovateBaseDao dataReportM_InnovateBaseDao;
	private int userId;
	private int type;
	private int funds_intensity;
	private String year;
	private double f_invest;
	private double f_tech;
	private double f_research;
	private double f_p;
	private double f_sale;

	/**
	 * @return the userId
	 */
	public int getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}

	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	/**
	 * @return the funds_intensity
	 */
	public int getFunds_intensity() {
		return funds_intensity;
	}

	/**
	 * @param funds_intensity
	 *            the funds_intensity to set
	 */
	public void setFunds_intensity(int funds_intensity) {
		this.funds_intensity = funds_intensity;
	}

	/**
	 * @return the year
	 */
	public String getYear() {
		return year;
	}

	/**
	 * @param year
	 *            the year to set
	 */
	public void setYear(String year) {
		this.year = year;
	}

	/**
	 * @return the f_invest
	 */
	public double getF_invest() {
		return f_invest;
	}

	/**
	 * @param f_invest
	 *            the f_invest to set
	 */
	public void setF_invest(double f_invest) {
		this.f_invest = f_invest;
	}

	/**
	 * @return the f_tech
	 */
	public double getF_tech() {
		return f_tech;
	}

	/**
	 * @param f_tech
	 *            the f_tech to set
	 */
	public void setF_tech(double f_tech) {
		this.f_tech = f_tech;
	}

	/**
	 * @return the f_research
	 */
	public double getF_research() {
		return f_research;
	}

	/**
	 * @param f_research
	 *            the f_research to set
	 */
	public void setF_research(double f_research) {
		this.f_research = f_research;
	}

	/**
	 * @return the f_p
	 */
	public double getF_p() {
		return f_p;
	}

	/**
	 * @param f_p
	 *            the f_p to set
	 */
	public void setF_p(double f_p) {
		this.f_p = f_p;
	}

	/**
	 * @return the f_sale
	 */
	public double getF_sale() {
		return f_sale;
	}

	/**
	 * @param f_sale
	 *            the f_sale to set
	 */
	public void setF_sale(double f_sale) {
		this.f_sale = f_sale;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		super.setContentType(super.JSON);
		Enterprise_Funds ef = new Enterprise_Funds();
		ef.setEditable(1);
		ef.setEnterprise_id(dataReportM_InnovateBaseDao.getEnterpriseBaseId(userId));
		ef.setFunds_base_investment(f_invest);
		ef.setFunds_check_pass(3);
//		ef.setFunds_id(1);
		ef.setFunds_income(f_sale);
		ef.setFunds_intensity(funds_intensity);
		ef.setFunds_is_new(0);
		ef.setFunds_ratio(f_p);
		ef.setFunds_research_investment(f_research);
		ef.setFunds_technology_investment(f_tech);
		ef.setFunds_type(type);
		ef.setFunds_year(year);
		ef.setWhichyear(year);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("funds_year", year);
		map.put("uid", userId);
		map.put("funds_type", type);
		if(dataReportM_InnovateBaseDao.isNewEnterprise_FundsExist(map)){
			super.outPrint("already");
			return "json";
		}
		if (dataReportM_InnovateBaseDao.addNewEnterprise_Funds(ef)) {
			super.outPrint("ok");
		} else {
			super.outPrint("fail");
		}
		return "json";
	}

}
